const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('edu_courses', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true
    },
    title: {
      type: DataTypes.STRING(30),
      allowNull: false,
      comment: "课程标题"
    },
    cat_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: "课程分类ID",
      references: {
        model: 'edu_categories',
        key: 'id'
      }
    },
    teacher: {
      type: DataTypes.STRING(40),
      allowNull: false,
      comment: "课程讲师姓名"
    },
    lesson_num: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "总课时"
    },
    brief: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: "课程简介，不超过100字"
    },
    cover_url: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "课程封面地址"
    },
    discounts: {
      type: DataTypes.DECIMAL(10,2),
      allowNull: false,
      comment: "课程售卖价格"
    },
    price: {
      type: DataTypes.DECIMAL(10,2),
      allowNull: false,
      comment: "课程原价"
    },
    sales: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: "销售数量"
    },
    discountsTag: {
      type: DataTypes.STRING(20),
      allowNull: true,
      comment: "活动标签，不超过10个字"
    },
    details: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: "课程详情，不超过100字"
    },
    view_count: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: "课程详情"
    },
    version: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: 1,
      comment: "乐观锁"
    },
    status: {
      type: DataTypes.STRING(10),
      allowNull: false,
      defaultValue: "Draft",
      comment: "Draft未发布  Normal已发布"
    },
    is_deleted: {
      type: DataTypes.TINYINT,
      allowNull: false,
      defaultValue: 0,
      comment: "逻辑删除 1（true）已删除， 0（false）未删除"
    }
  }, {
    sequelize,
    tableName: 'edu_courses',
    timestamps: true,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "cat_id",
        using: "BTREE",
        fields: [
          { name: "cat_id" },
        ]
      },
    ]
  });
};
